﻿Imports MICROFORMA.BEL
Imports MICROFORMA.BLL

Public Class frmIndexAdd

#Region "Declaracion de constantes"
    Const constTexto As String = "Texto"
    Const constNumericosinDecimales As String = "Numero sin Decimales"
    Const constNumericoconDecimales As String = "Numero con Decimales"
    Const constFechaHora As String = "Fecha - Hora"
    Const constVerdaderoFalso As String = "Verdadero - Falso"
    Const constListaSeleccion As String = "Lista Seleccion"
    Const constListaMultiseleccion As String = "Lista Multiseleccion"
    Const constGrilla As String = "Grilla"
    Const constTipoArchivo As String = "Tipo Archivo"
#End Region

    Public bolUpdate As Boolean
    Public idIndice As Int16
    Public IdTipoDocumental As Integer
    Public NombreTipoDocumental As String

    Dim indicesBE As IndicesBE
    Dim indicesBL As IndicesBL
    Dim tipoDatoBL As TipoDatoBL
    Dim strMask As String
    Dim typeData As String
    Dim strItemsChkListVar As String
    Dim dTableIndex As DataTable
    Dim strArrayIndicesGrilla As ArrayList

    Sub New()

        tipoDatoBL = New TipoDatoBL
        indicesBL = New IndicesBL
        'tipoDatoBE = New TipoDatoBE
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub frmIndexAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TabControl1.TabPages.Remove(TabControl1.TabPages(2))
        TabControl1.TabPages.Remove(TabControl1.TabPages(2))
        Call loadcontrols()

        If bolUpdate Then
            dTableIndex = indicesBL.List(idIndice) 'ListasBL.List(idLista)
            LoadChkLists()
            txtName.Enabled = False
            cboTypeData.Enabled = False
            'Call LoadComboNamesConnections()
            'Call LoadComboFather()
            'Call LoadCombos(dtableLista)
        Else
            Call EnableControls(chkValueDefault.CheckState)
        End If

        txtName.Focus()

    End Sub

    Private Sub LoadChkLists()
        Dim bolTieneDefault As Boolean
        For Each dtrFila As DataRow In dTableIndex.Rows

            txtName.Text = dtrFila("Nombre")
            txtNameInternal.Text = dtrFila("NombreInterno")
            strMask = dTableIndex.Rows(0)("MascaraEntrada") & ""
            cboTypeData.SelectedIndex = CInt(dtrFila("IdTipoDato"))

            chkValueDefault.Checked = True
            bolTieneDefault = False

            If dtrFila("CorrelativoValor") & "" <> "" Then
                txtCorrelativoValue.Text = dtrFila("CorrelativoValor")
                rdbCorrelativy.Checked = True
                rdbIncrementaly.Checked = IIf(CBool(dtrFila("CorrelativoSumar")) = True, True, False)
                rdbSubtract.Checked = Not rdbIncrementaly.Checked
                bolTieneDefault = True
            End If

            If dtrFila("ConsultaSqlExterna") & "" <> "" Then
                txtQueryDB.Text = dtrFila("ConsultaSqlExterna")
                rdbQueryDB.Checked = True
                bolTieneDefault = True
            End If

            Select Case cboTypeData.Text
                Case constTexto
                    If dtrFila("Prefijo") & "" <> "" Then
                        txtPrefijo.Text = dtrFila("Prefijo")
                        chkPrefijo.Checked = True
                        rdbStart.Checked = IIf(CBool(dtrFila("PrefijoAdelante")) = True, True, False)
                        rdbEnd.Checked = Not rdbStart.Checked
                        bolTieneDefault = True
                    End If
                    If dtrFila("CadenaVariables") & "" <> "" Then
                        txtCreateIndiceSystem.Text = dtrFila("CadenaVariables")
                        rdbCreateIndiceSystem.Checked = True
                        bolTieneDefault = True
                    End If
                Case constNumericosinDecimales, constNumericoconDecimales
                    If dtrFila("RangoInicio") & "" <> "" Then
                        txtFrom.Text = dtrFila("RangoInicio")
                        txtTo.Text = dtrFila("RangoFin")
                    End If
                Case constListaSeleccion, constListaMultiseleccion
                    cboList.SelectedIndex = CInt(dtrFila("IdLista"))
                Case constGrilla
                    AddItemCheckedList(dtrFila("IndicesGrilla"))

            End Select

            If Not bolTieneDefault Then
                chkValueDefault.Checked = False
            End If


            'opciones
            rdbNotDupliqued.Checked = IIf(CBool(dtrFila("Duplicado")) = True, True, False)
            rdbIndexingObligatory.Checked = IIf(CBool(dtrFila("Obligatorio")) = True, True, False)
            rdbDoubleDigitation.Checked = IIf(CBool(dtrFila("DobleDigitacion")) = True, True, False)


            'rdbListsDI.Checked = IIf(Convert.ToBoolean(dtrFila("ListaInterna")), True, False)
            'rdbListsDE.Checked = IIf(Convert.ToBoolean(dtrFila("ListaInterna")), False, True)
            'strText = UnReplaceItemsContent(dtrFila("Contenido"))
            'Call AddItemCheckedList(strText)

            'If rdbListsDE.Checked Then
            '    cboNameConexion.SelectedValue = dtrFila("IdDatoExterno")
            '    cboDataMember.SelectedText = dtrFila("CampoMostrar")
            '    cboDataValue.SelectedText = dtrFila("CodigoInterno")
            '    'strText = dtrFila("Contenido")
            '    'chkListBoxLists.Text = Split(dtrFila("Contenido"), " ").ToString
            '    cboListFather.SelectedValue = dtrFila("ListaPadre")
            '    cboListsFatherRelation.SelectedValue = dtrFila("CampoRelacionPadre")
            'End If

        Next
        'listasBL = Nothing

    End Sub

    Private Sub loadcontrols()
        Dim table As DataTable = tipoDatoBL.GetList

        cboTypeData.Items.Insert(0, "[ Seleccione ]")

        For i As Int16 = 0 To table.Rows.Count - 1
            'cboTypeData.Items.Insert(i + 1, table.Rows(i).Item("Nombre"))
            cboTypeData.Items.Insert(table.Rows(i).Item("IdTipoDato"), table.Rows(i).Item("Nombre"))
        Next

        cboTypeData.SelectedIndex = 0

    End Sub

    'Private Sub loadcontrols()
    '    cboTypeData.DataSource = tipoDatoBL.GetList
    '    cboTypeData.ValueMember = "IdTipoDato"
    '    cboTypeData.DisplayMember = "Nombre"
    'End Sub

    Private Sub btnMask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMask.Click
        If cboTypeData.SelectedIndex <> -1 Then
            Dim _frmMask As New frmMask(cboTypeData.Text)
            _frmMask.strMask = strMask
            _frmMask.ShowDialog()
            strMask = _frmMask.strMask
            _frmMask.Dispose()
        End If
    End Sub

    Private Sub chkValueDefault_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkValueDefault.CheckedChanged
        If chkValueDefault.Checked Then
            Call SetStateRadioButtons()
            Call ActivateControls(getEnableRadioButton, chkValueDefault.CheckState)
        End If
        Call EnableControls(chkValueDefault.CheckState)
    End Sub

    Private Sub SetStateRadioButtons()
        rdbCreateIndiceSystem.Checked = False
        rdbQueryDB.Checked = False
        rdbCorrelativy.Checked = False
    End Sub

    Private Function getEnableRadioButton() As System.Object
        If rdbCorrelativy.Checked Then
            Return grpBoxCorrelativy
        ElseIf rdbCreateIndiceSystem.Checked Then
            Return grpBoxCreateIndiceSystem
        ElseIf rdbQueryDB.Checked Then
            Return grpBoxQueryDB
        End If
    End Function

    Private Sub EnableControls(ByVal flag As Boolean)
        rdbCorrelativy.Enabled = flag
        rdbCreateIndiceSystem.Enabled = flag
        rdbQueryDB.Enabled = flag
        grpBoxCorrelativy.Enabled = flag
        grpBoxCreateIndiceSystem.Enabled = flag
    End Sub


    Private Sub rdbCorrelativy_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbCorrelativy.CheckedChanged, chkValueDefault.CheckedChanged, MyBase.Load
        ActivateControls(grpBoxCorrelativy, rdbCorrelativy.Checked)
    End Sub

    Private Sub rdbCreateIndiceSystem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbCreateIndiceSystem.CheckedChanged, chkValueDefault.CheckedChanged, MyBase.Load
        ActivateControls(grpBoxCreateIndiceSystem, rdbCreateIndiceSystem.Checked)
    End Sub

    Private Sub rdbQueryDB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbQueryDB.CheckedChanged, chkValueDefault.CheckedChanged, MyBase.Load
        ActivateControls(grpBoxQueryDB, rdbQueryDB.Checked)
    End Sub

    Private Sub ActivateControls(ByVal sender As System.Object, ByVal flag As Boolean)
        If Not sender Is Nothing Then
            CType(sender, Control).Enabled = flag
        End If
        If chkValueDefault.Checked = False Then
            CType(sender, Control).Enabled = False
        End If
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        If ValidateForm() Then
            indicesBE = setEntity()

            If bolUpdate Then
                If indicesBL.Update(indicesBE) = "OK" Then
                    Call MessageMistake("El indice se actualizó correctamente.", True)
                    Me.Close()
                Else
                    Call MessageMistake("No se pudo actualizar el indice correctamente. ")
                End If
            Else
                If indicesBL.Add(indicesBE) = "OK" Then
                    Call MessageMistake("El indice se creo correctamente.", True)
                    Me.Close()
                Else
                    Call MessageMistake("El indice no se pudo crear correctamente.")
                End If
            End If

        End If
    End Sub

    Private Function SetEntityIndiceGrilla() As IndiceGrillaBECollection

        Dim indiceGrillaBECollection As New IndiceGrillaBECollection

        For index As Integer = 0 To strArrayIndicesGrilla.Count - 1
            Dim indiceGrillaBE As New IndiceGrillaBE
            indiceGrillaBE.Indice = CStr(strArrayIndicesGrilla.Item(index))
            indiceGrillaBE.Orden = index + 1
            indiceGrillaBECollection.Add(indiceGrillaBE)
            indiceGrillaBE = Nothing
        Next

        Return indiceGrillaBECollection

    End Function

    Private Function setEntity() As IndicesBE
        Dim indiceBE As New IndicesBE

        indiceBE.IdTipoDocumental = IdTipoDocumental
        indiceBE.NombreTipoDocumental = NombreTipoDocumental
        indiceBE.Nombre = txtName.Text
        indiceBE.NombreInterno = "SCF" & txtName.Text.Replace(" ", "")
        indiceBE.IdTipoDato = CInt(cboTypeData.SelectedIndex)
        'Validar que si el Tipo de Dato es List se llene este campo de la entidad
        'indiceBE.IdLista = CInt(cboList.SelectedValue)
        indiceBE.MascaraEntrada = strMask
        indiceBE.DobleDigitacion = rdbDoubleDigitation.Checked
        indiceBE.Duplicado = rdbNotDupliqued.Checked
        indiceBE.Obligatorio = rdbIndexingObligatory.Checked

        Select Case cboTypeData.Text
            Case constFechaHora '4
                indiceBE.MascaraEntrada = strMask
                indiceBE.FormatoFecha = "" 'Falta Validar
            Case constGrilla '8
                indiceBE.IndicesGrillaCollection = SetEntityIndiceGrilla()
            Case constListaMultiseleccion '7
                indiceBE.IdLista = CInt(cboList.SelectedValue) 'Preguntar: ¿q se va a realizar?
            Case constListaSeleccion '6
                indiceBE.IdLista = CInt(cboList.SelectedValue)
            Case constNumericoconDecimales, constNumericosinDecimales '2
                indiceBE.MascaraEntrada = strMask
                indiceBE.RangoInicio = txtFrom.Text
                indiceBE.RangoFin = txtTo.Text
            Case constNumericosinDecimales '3
                indiceBE.MascaraEntrada = strMask
                indiceBE.RangoInicio = txtFrom.Text
                indiceBE.RangoFin = txtTo.Text
            Case constTexto '1
                indiceBE.MascaraEntrada = strMask
            Case constTipoArchivo '9
                indiceBE.IdTipoDato = CInt(cboTypeData.SelectedIndex)
            Case constVerdaderoFalso '5
                indiceBE.MostrarComoRadio = IIf(rdbRadioButton.Checked, True, False)
        End Select

        If chkValueDefault.Checked Then
            If rdbCorrelativy.Checked Then
                If chkPrefijo.Checked Then
                    indiceBE.Prefijo = txtPrefijo.Text
                    indiceBE.PrefijoAdelante = If(rdbStart.Checked, True, False)
                End If
                indiceBE.CorrelativoValor = CInt(txtCorrelativoValue.Text)
                indiceBE.CorrelativoSumar = If(rdbIncrementaly.Checked, True, False)

            End If
            If rdbCreateIndiceSystem.Checked Then
                indiceBE.CadenaVariables = txtCreateIndiceSystem.Text
            End If
            If rdbQueryDB.Checked Then
                indiceBE.ConsultaSQLExterna = txtQueryDB.Text
                'indiceBE.IdDatoExterno = 1 'Todo HardCode
            End If

        End If

        indiceBE.TipoIndexacion = GetTypeIndexacion()
        indiceBE.ValueDefault = chkValueDefault.Checked
        indiceBE.Correlativy = rdbCorrelativy.Checked
        indiceBE.PrefijoBol = chkPrefijo.Checked
        indiceBE.CreateIndice = rdbCreateIndiceSystem.Checked
        indiceBE.QueryDB = rdbQueryDB.Checked
        indiceBE.ZoomAutomatico = chkDoZoom.Checked

        Return indiceBE

    End Function

    Private Function GetTypeIndexacion() As Char
        'TipoIndexacion: 1=OCR, 2=ICR, 3=Barcode, 4=Ninguno
        Dim chrTypeIndexacion As Char = "4"

        If rdbOCR.Checked Then
            chrTypeIndexacion = "1"
        ElseIf rdbICR.Checked Then
            chrTypeIndexacion = "2"
        ElseIf rdbBarCode.Checked Then
            chrTypeIndexacion = "3"
        End If

        Return chrTypeIndexacion

    End Function

    Private Function ValidateForm() As Boolean

        'Pestaña General
        If Trim(txtName.Text) = "" Then
            Call MessageMistake("Por Favor ingrese un nombre para el indice.")
            txtName.Focus()
            Exit Function
        End If

        'Valida Existencia de indice
        If Not bolUpdate Then
            dTableIndex = indicesBL.ListByName(txtName.Text, IdTipoDocumental)
            If dTableIndex.Rows.Count > 0 Then 'ListasBL.List(idLista)
                Call MessageMistake("Nombre de indice ya existe.")
                txtName.Focus()
                Exit Function
            End If
        End If

        If cboTypeData.SelectedIndex = 0 Then
            Call MessageMistake("Por favor seleccione un tipo de dato del listado.")
            cboTypeData.Focus()
            Exit Function
        ElseIf cboTypeData.Text = constListaSeleccion Or cboTypeData.Text = constListaMultiseleccion Then
            If cboList.SelectedIndex = 0 Then
                Call MessageMistake("Por favor seleccione un elemento del listado de la lista para asociarlo al tipo de dato seleccionado.")
                Exit Function
            End If
        End If
        'If cboList.SelectedIndex = 0 Then
        '    Call MessageMistake("Por favor seleccione un elemento del listado de listas.")
        '    cboList.Focus()
        '    Exit Function
        'End If

        If (txtFrom.Text > txtTo.Text) And (cboTypeData.SelectedIndex = 2 Or cboTypeData.SelectedIndex = 3) Then
            Call MessageMistake("El valor de inicio de un rango no puede ser mayor al valor final.")
            Exit Function
        End If

        'Pestaña Valores por Defecto
        If chkValueDefault.Checked Then
            If rdbCorrelativy.Checked Then
                If chkPrefijo.Checked Then
                    If Trim(txtPrefijo.Text) = "" Then
                        Call MessageMistake("Por favor ingrese un prefijo para el correlativo del indice.")
                        txtPrefijo.Focus()
                        Exit Function
                    End If
                    If Not (rdbStart.Checked Or rdbEnd.Checked) Then
                        Call MessageMistake("Por favor indique si el prefijo se aplicará al inicio o final.")
                        rdbStart.Focus()
                        Exit Function
                    End If
                ElseIf chkPrefijo.CheckState = CheckState.Unchecked Then
                    If Trim(txtCorrelativoValue.Text) = "" Then
                        Call MessageMistake("Por favor ingrese un valor para el correlativo del prefijo.")
                        Exit Function
                    End If
                    If Not (rdbIncrementaly.Checked Or rdbSubtract.Checked) Then
                        Call MessageMistake("Por favor indique si el valor se incrementará o restará.")
                        rdbIncrementaly.Focus()
                        Exit Function
                    End If
                End If
            End If
            If rdbCreateIndiceSystem.Checked Then
                If Trim(txtCreateIndiceSystem.Text) = "" Then
                    Call MessageMistake("Por favor elija los valores correspondientes presionando el boton Agregar variables.")
                    btnCreateIndiceSystem.Focus()
                    Exit Function
                End If
            End If
            If rdbQueryDB.Checked Then
                If Trim(txtQueryDB.Text) = "" Then
                    Call MessageMistake("Por favor obtenga la consulta para establecer los valores presionando el boton Agregar consulta.")
                    btnQueryDB.Focus()
                    Exit Function
                End If
            End If
        End If
        'Pestaña Indexación Automatica
        If Not (rdbOCR.Checked Or rdbICR.Checked Or rdbBarCode.Checked Or rdbDisable.Checked) Then
            Call MessageMistake("Por favor indique que tipo de indexación tendra el indice.")
            rdbDisable.Focus()
            Exit Function
        End If



        ValidateForm = True

    End Function

    Private Sub txtCorrelativyValue_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCorrelativoValue.KeyPress
        Call SoloNumeros(e)
    End Sub

    Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
        Call SoloAlfanumerico(e)
    End Sub

    Private Sub SetListVariablesInTextBoxIndicesSystem(ByVal strListVariables As String)

        If strListVariables.Length > 0 Then
            Dim StrNewListVariables As String = Replace(strListVariables, ",", vbNewLine)

            Dim StrArrayItemsVariables As String() = Split(StrNewListVariables.Trim, vbNewLine)

            txtCreateIndiceSystem.Text = String.Join(vbNewLine, StrArrayItemsVariables)
        End If

    End Sub

    Private Sub cboTypeData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTypeData.SelectedIndexChanged
        If cboTypeData.SelectedIndex <> -1 Then

            Call viewGroupBox()

            chkPrefijo.Enabled = True
            rdbCreateIndiceSystem.Visible = True
            txtPrefijo.Enabled = True
            chkValueDefault.Enabled = True

            If cboTypeData.Text = constListaSeleccion Or cboTypeData.Text = constListaMultiseleccion Then
                Call LoadList()
                grpBoxLists.Visible = True
            ElseIf cboTypeData.Text = constGrilla Then
                grpBoxGrilla.Visible = True
                chkValueDefault.Enabled = False
            ElseIf cboTypeData.Text = constNumericoconDecimales Or cboTypeData.Text = constNumericosinDecimales Then
                grpBoxNumeric.Visible = True
                chkPrefijo.Enabled = False
                rdbCreateIndiceSystem.Visible = False
                txtPrefijo.Enabled = False
            ElseIf cboTypeData.Text = constTipoArchivo Then

            ElseIf cboTypeData.Text = constFechaHora Then
                btnMask.Visible = True
            ElseIf cboTypeData.Text = constVerdaderoFalso Then
                grpBoxViewHow.Visible = True
            ElseIf cboTypeData.Text = constTexto Then
                btnMask.Visible = True
            End If
        End If
    End Sub

    Private Sub viewGroupBox()
        grpBoxGrilla.Visible = False
        grpBoxNumeric.Visible = False
        grpBoxLists.Visible = False
        grpBoxViewHow.Visible = False
        btnMask.Visible = False
    End Sub

    Private Sub LoadList()

        Dim listasBL As New ListasBL
        Dim table As DataTable = listasBL.List

        cboList.ValueMember = "IdLista"
        cboList.DisplayMember = "Nombre"

        Dim dRow As DataRow
        dRow = table.NewRow
        dRow("IdLista") = 0
        dRow("Nombre") = "[ Seleccione ]"

        table.Rows.Add(dRow)
        table.DefaultView.Sort = "IdLista"
        cboList.DataSource = table

    End Sub

    Private Function getTypeData() As String
        Select Case typeData
            Case constTexto
                Return constTexto
            Case constNumericoconDecimales
                Return constNumericoconDecimales
            Case constNumericosinDecimales
                Return constNumericosinDecimales
            Case constListaSeleccion
                Return constListaSeleccion
            Case constListaMultiseleccion
                Return constListaMultiseleccion
            Case constFechaHora
                Return constFechaHora
            Case constVerdaderoFalso
                Return constVerdaderoFalso
            Case constTipoArchivo
                Return constTipoArchivo
            Case constGrilla
                Return constGrilla
        End Select
    End Function

    Private Sub btnAddIndice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddIndice.Click
        Dim _frmAddListVariables As New frmAddListVariables
        _frmAddListVariables.IdTipoDocumental = IdTipoDocumental
        _frmAddListVariables.ShowDialog()
        If _frmAddListVariables.strListVariables.Length > 0 Then
            AddItemCheckedList(UnReplaceItemsContent(_frmAddListVariables.strListVariables))
            'validar cuando es tipo grilla
            If _frmAddListVariables.strListIndices.Length > 0 Then
                Call SetSaveIndices(_frmAddListVariables.strListVariables)
            End If
        End If
        _frmAddListVariables.Dispose()
    End Sub

    Private Sub SetSaveIndices(ByVal strListIndices As String)
        Dim strIndicesGrilla As String()
        strArrayIndicesGrilla = New ArrayList

        strIndicesGrilla = Split(strListIndices.Trim(","), ",")

        For i As Int16 = 0 To strIndicesGrilla.Length - 1
            strArrayIndicesGrilla.Add(strIndicesGrilla(i))
        Next

    End Sub

    Private Sub AddItemCheckedList(ByVal stringText As String)
        If stringText.Length > 0 Then
            Dim a As String()
            chkListVar.Items.Clear()
            a = Split(stringText.Trim, vbNewLine)
            chkListVar.Items.AddRange(a)
        End If
    End Sub

    Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
        txtNameInternal.Text = "SCF" & Trim(txtName.Text)
    End Sub

    Private Sub btnQueryDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQueryDB.Click
        Dim _frmDataExternal As New frmDataExternal
        _frmDataExternal.txtQuerySql.Text = txtQueryDB.Text
        _frmDataExternal.ShowDialog()
        If _frmDataExternal.ValidaTestQuery Then
            txtQueryDB.Text = _frmDataExternal.txtQuerySql.Text
        End If
        _frmDataExternal.Dispose()
    End Sub

    Private Function ReplaceItemsContent(ByVal stringText As String) As String
        Return Replace(stringText, vbNewLine, " ")
    End Function

    Private Function UnReplaceItemsContent(ByVal stringText As String) As String
        Return Replace(stringText, ",", vbNewLine)
    End Function

    Private Sub btnDeleteIndice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If chkListVar.CheckedItems.Count > 0 Then
            Call DeleteItemsChlList()
            Call AddItemCheckedList(strItemsChkListVar)
        End If
    End Sub

    Private Sub DeleteItemsChlList()
        Dim countItems As Integer

        For countItems = chkListVar.Items.Count - 1 To 0 Step -1
            If chkListVar.GetItemCheckState(countItems) = CheckState.Checked Then
                chkListVar.Items.RemoveAt(countItems)
                If strArrayIndicesGrilla.Count > 0 Then
                    strArrayIndicesGrilla.RemoveAt(countItems)
                End If
            End If

        Next

        strItemsChkListVar = getStringCollectionChkList()

    End Sub

    Private Function getStringCollectionChkList() As String
        Dim strListItem(chkListVar.Items.Count - 1) As String

        For i As Int32 = 0 To chkListVar.Items.Count - 1
            strListItem(i) = chkListVar.Items(i).ToString
        Next

        Dim strListItems As String = String.Join(vbNewLine, strListItem)

        Return strListItems

    End Function

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub


    Private Sub btnCreateIndiceSystem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateIndiceSystem.Click
        Dim _frmAddListVariables As New frmAddListVariables(True)
        _frmAddListVariables.ShowDialog()

        If _frmAddListVariables.lstListVar.SelectedItems.Count > 0 Then
            Call SetListVariablesInTextBoxIndicesSystem(_frmAddListVariables.strListVariables)
        End If

        _frmAddListVariables.Dispose()

    End Sub
End Class